package cn.tedu.opp;

import java.util.Scanner;

/**
 * @author ：Dsi
 * @date ：2021/11/20 14:17
 * Describe ：已知:斐波那契数列的前几个数分别为0,1,1,2,3,5…
 * 从第三项开始,每一项都等于前两项的和.请接收用户输入的整数n,求出此数列的前n项.
 */
public class TestOpp {
    public static void main(String[] args) {
        m();
    }

    private static void m() {
        System.out.println("请输入整数列个数：");
        int a=new Scanner(System.in).nextInt();
        
        if(a==1){
            System.out.print("0"+"\t");
        }else if(a==2){
            System.out.print("0,1"+"\t");
        }else if(a>=3){
            System.out.print("0,1,1"+"\t");
        }
        if(a>3){
            int a2=0,b=1,c=1;
            for (int i = 4; i <= a; i++,b=c,c=a2) {
                a2=b+c;
                System.out.print(a2+"\t");
            }
        }

    }
}

